

#ifndef __CE_PARTICELNODE_H__
#define __CE_PARTICELNODE_H__

#include <cegfx/cegeometrynode.h>
#include <cegfx/ceparticelmesh.h>
#include <d3dx9.h>


class CE_GFX_API ceParticelNode : public virtual ceGeometryNode
{
	IQF_DECLARATION;
public:
	struct Configuration
	{
		D3DXVECTOR2	ParticelDimension;

		D3DXVECTOR3 Pos;
		D3DXVECTOR3	PosVariance;
		D3DXVECTOR3 Direction;
		D3DXVECTOR3	DirectionVariance;
		D3DXVECTOR3 Gravity;
		float				Rotation;
		float				RotationVariance;

		float				ParticelsPerSecond;
		unsigned		MaxParticels;
		unsigned		TimeToLive;
		unsigned		TimeToLiveVariance;
		float				AlphaBlend;

		unsigned		BoundingBoxUpdateInterval;

		ceMaterial*	Material;
	};
private:
	struct Particel
	{
		D3DXVECTOR3	pos;
		D3DXVECTOR3 dir;
		float				timeToLive;
		float				alphaBlendTime;
		float				rotation;
		float				rotationSpeed;
	};

	std::vector<Particel>	particels;
	ceParticelMesh*	mesh;

	float					createInterval;
	Configuration config;

	bool					generate;
	unsigned			boundingBoxUpdate;

	float					createTime;

	void initializeParticel (Particel& particel);
public:
	ceParticelNode();
	~ceParticelNode();
	bool Configure (LPDIRECT3DDEVICE9 device, const Configuration& config);
	void SetEmitting(bool emitting);
	bool IsEmitting () const;

	virtual void Update (const ceUpdateEnv& env);
};


#endif /* ! __CE_PARTICELNODE_H__*/
